Skip to content

Fix stack overflow in error generation for recursive mapped types#63215

Closed
hamzax180 wants to merge 1 commit intomicrosoft:mainfrom
hamzax180:fix/issue-63090
Closed

Fix stack overflow in error generation for recursive mapped types#63215
hamzax180 wants to merge 1 commit intomicrosoft:mainfrom
hamzax180:fix/issue-63090

Conversation

@hamzax180
Copy link

Fixes #63090

Bug Description

When a mapped type contains a deeply recursive or circular reference, TypeScript correctly identifies it as an error. However, when generating the diagnostic message (Type_of_property_0_circularly_references_itself_in_mapped_type_1), the compiler calls typeToString(mappedType) to format the error text.

Evaluating typeToString(mappedType) triggers property resolution, which evaluates the symbol's type by calling getTypeOfMappedSymbol again. Since symbol.links.type hasn't been cached with the errorType yet, this hits the same circularity, which attempts to throw another error, triggering typeToString again, leading to an infinite cycle and an eventual RangeError: Maximum call stack size exceeded.

Fix Explanation

This PR breaks the infinite recursion by eagerly caching symbol.links.type = errorType; immediately before calling error(...) and typeToString(mappedType).

When typeToString evaluates the mapped type, it now sees the cached errorType for the symbol and safely halts recursion, generating the correct error message without blowing up the call stack.

Testing

Added the provided reproduction from the issue as a compiler test case:

  • tests/cases/compiler/issue63090.ts
  • Ran hereby baseline-accept so the baseline error generation accurately outputs the circularity error instead of crashing.

@hamzax180
Copy link
Author

@microsoft-github-policy-service agree

@hamzax180 hamzax180 closed this Mar 7, 2026
@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 7, 2026
@hamzax180 hamzax180 reopened this Mar 7, 2026
@github-project-automation github-project-automation bot moved this from Done to Not started in PR Backlog Mar 7, 2026
Copy link
Author

@hamzax180 hamzax180 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all wishes

@typescript-bot
Copy link
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Crash: RangeError: Maximum call stack size exceeded during type serialization of recursive distributive mapped types

2 participants